<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
import { useUserStore } from '@/store'
import { getUrlQuery } from '@/utils'
import { getToken, setToken } from './utils/auth'
import { getHomeUrl } from '@/service/index/login'

const userStore = useUserStore()

onLaunch(async () => {
  // console.log('App Launch')
  const code = getUrlQuery('code')
  const isDev = import.meta.env.DEV

  // 调试
  if (isDev) {
    setToken(
      'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJTaGlOaW5nTmluZyIsImxvZ2luX3VzZXJfa2V5IjoiMWY5YzYzMzAtMDIzMS00YTdmLWI0OGYtZjg4M2Y3NGQ0NGRjIn0.0hVTbJHvEKfqJhaIzZMQke1es8KpcS9s-U5PLSpYwqNn2AzHBhc2whNScZ4Ij3WlvCI4zWa0GFh6PcJo6vLCNw',
    )
  } else {
    if (!getToken() && !code) {
      window.sessionStorage.setItem('optionsPath', window.location.href)
      const { data } = await getHomeUrl()
      window.location.replace(data as string)
    }
  }
})
onShow(() => {
  // console.log('App Show')
})
onHide(() => {
  // console.log('App Hide')
})
</script>

<style lang="scss">
/* stylelint-disable selector-type-no-unknown */
button::after {
  border: none;
}

swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 单行省略，优先使用 unocss: text-ellipsis
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 两行省略
.ellipsis-2 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

// 三行省略
.ellipsis-3 {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
</style>
